﻿//商品类别
window.operateEvents = {
    'click .viewxx': function (e, value, row, index) {
        MyDialog.viewform("SpeList/ViewOrder.html?ID=" + row.OrderID, "查看详细内容");
    }
};
var option = {};
option.columns = [

{ title: '订单号', field: 'OrderID' },
{ title: '应付金额(元)', field: 'PayPrice' },
{ title: '收货人', field: 'Receiver' },
{
    title: '地址', field: 'Province',
    formatter: function (value, row) {
        return row.Province + row.City + row.County + row.Address;
    }
},
{ title: '电话', field: 'Telephone' },
{ title: '快递方式', field: 'ExpressWay' },
{
    title: '操作', field: 'CreateUser', formatter: function (value, row, index) {

        if (row.State == "1") {
            return "<a  class='fh' href='#' dataid='" + row.ID + "' rowindex='" + index + "'>发货</a>";
        }
        if (row.State == "0" && row.ExpressWay == "上门自取") {
            return "<a  class='sh' href='#' dataid='" + row.ID + "' rowindex='" + index + "'>收货</a>";
        }
    }
},
{ title: '快递公司', field: 'Express' },
{ title: '快递单号', field: 'ExpressNo' },
{
    title: '订单状态', field: 'State', formatter: function (value, row, index) {
        if (row.State == "0") {
            return "新订单，未支付";
        }
        if (row.State == "1") {
            return "已支付，待发货";
        }
        if (row.State == "2") {
            return "已发货，待收货";
        } if (row.State == "3") {
            return "已确认收货";
        } if (row.State == "9") {
            return "已取消";
        }
    }
},
{
    title: '订单明细', field: 'OrderMemo', formatter: function (value, row) {
        var html = "";
        html = '<a href="#" style="margin-left:10px" class="viewxx" >详细内容</a>';
        return html;
    },
    events: operateEvents
}

];


$(document).ready(function () {

    $(".addForm,.EditForm,.DelForm").remove();
    $(".fh").YanTip({
        title: "发货",
        place: "top",
        content: '<div class="row"><div class="col-xs-12"><div class="form-group"><label>快递公司</label> <input type="text" value="" class="form-control kdgs" /></div><div class="form-group"><label>快递单号</label> <input type="text" value="" class="form-control kddh" /></div></div></div>',
        showed: function ($tip) {
        },
        confirm: function ($tip, $dom) {
            var dataid = $dom.attr("dataid");
            var rowindex = $dom.attr("rowindex");
            var kdgs = $tip.find('.kdgs').val();
            var kddh = $tip.find('.kddh').val();
            if (kdgs != "" && kddh != "") {
                $.post("../SpeList/DLLAjaxHandler.ashx", { Action: "DD_FH", id: dataid, kdgs: kdgs, kddh: kddh },
                     function (data) {
                         if (data == "success") {
                             $("#FTGrid").bootstrapTable('updateRow', {
                                 index: rowindex,
                                 row: {
                                     Express: kdgs,
                                     ExpressNo: kddh,
                                     CreateUser: "-"

                                 }
                             });
                             $(".Yan_tip").remove();
                             toastr.success("操作成功");

                         } else {
                             toastr.error("操作失败");
                         }
                     });
            } else {
                alert("请输入快递公司或快递单号");
            }
        }
    });
    $(".sh").YanTip({
        title: "收货",
        place: "top",
        content: '<div class="row"><div class="col-xs-12"><div class="form-group"><label>取货人</label> <input type="text" value="" class="form-control qhr" /></div><div class="form-group"><label>备注</label> <input type="text" value="" class="form-control qhbz" /></div></div></div>',
        showed: function ($tip) {
        },
        confirm: function ($tip, $dom) {
            var dataid = $dom.attr("dataid");
            var rowindex = $dom.attr("rowindex");
            var qhr = $tip.find('.qhr').val();
            var qhbz = $tip.find('.qhbz').val();

            $.post("../SpeList/DLLAjaxHandler.ashx", { Action: "DD_SH", id: dataid, qhr: qhr, qhbz: qhbz },
          function (data) {
              if (data == "success") {
                  $("#FTGrid").bootstrapTable('updateRow', {
                      index: rowindex,
                      row: {
                          State: '3'
                      }
                  });
                  $(".Yan_tip").remove();
                  toastr.success("操作成功");

              } else {
                  toastr.error("操作失败");
              }
          });


        }
    });
})